<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('监督项列表')" />
</head>
<body>
<div th:fragment="auBatchItemList">
    <div id="voucherInfoDiv">
        <div class="box" style="width:20%;left: 15px;top: -5px">
            <div class="box-main">
                <form id="formId">
                    <input name="batchId" id="batchId" value="" type="hidden"/>
                </form>
                <table width="100%" border="0" cellpadding="0"
                       cellspacing="0" align="center">
                    <div>
                        <table id="bootstrap-table"></table>
                    </div>
                </table>
            </div>
            <th:block th:include="include :: footer" />
            <script th:inline="javascript">
                var prefix = ctx + "oms/paeaAuAuditItem";
                var datas = [[${@dict.getType('paea_audit_Item_state')}]];
                var paeaAutypeName;
                var paeaAuAuditItemIndex = 0;
                var viewer;
                var sdiImageList;
                $(function() {
                    var options = {
                        url: prefix + "/auditWrapperTable",
                        height:$(window).height()-235,
                        pagination:false,
                        showSearch: false,
                        showRefresh: false,
                        showToggle: false,
                        showColumns: false,
                        showFooter: false,
                        reorderableRows: true,
                        useRowAttrFunc: true,
                        onClickRow: function(row, $element){
                            paeaAuAuditItemIndex = $element.data('index');
                            displayItemInfos(row);
                        },
                        //启用点击选中行
                        clickToSelect: true,
                        columns: [{
                            radio: true
                        },
                            {
                                field : 'id',
                                title : '主键',
                                visible: false
                            },
                            {
                                field : 'trDate',
                                title : '日期',
                                visible: false
                            },
                            {
                                field : 'tellerId',
                                title : '柜员',
                                visible: false
                            },
                            {
                                field : 'dsTradeId',
                                title : '流水ID',
                                visible: false
                            },
                            {
                                field : 'auTypeId',
                                title : '监督类型',
                                visible: false
                            },
                            {
                                field : 'vchNo',
                                title : '流水号'
                            },
                            {
                                field : 'state',
                                title : '监控标识',
                                align: 'center',
                                formatter: function(value, row, index) {
                                    return $.table.selectDictLabel(datas, value);
                                }
                            }],
                        onLoadSuccess:function(data){
                            g_radioValue = "1";//初始未监控
                            document.getElementById("auditType1").checked = "checked";
                            showRows('1');//初始加载数据后，才能执行showRows
                        },
                    };
                    $.table.init(options);
                })
                //初始化点击按钮   点击radio触发事件 onCheck事件未生效
                $('#bootstrap-table').on('check.bs.table', function (e,row, $element) {
                    paeaAuAuditItemIndex = $element.data('index');
                    displayItemInfos(row);
                });

                function refreshBT(row)
                {
                    if(isViewOnly == "false"){// isViewOnly == “true” 时，不做按钮的disabled 变化，一律为不显示
                        if(row.state=="3") {//AuditItemState.HAVE_ERROR.getCode() 督办
                            document.all.createErrBT.disabled = true;
                            document.all.normalBT.disabled = true;
                            document.all.cancelBT.disabled = true;
                        } else {
                            document.all.createErrBT.disabled = false;
                            document.all.normalBT.disabled = false;
                        }

                        if(row.state=="1") {//<%=AuditItemState.UN_AUDIT.getCode()%> 未监控
                            document.all.cancelBT.disabled = true;
                            document.all.normalBT.disabled = false;
                        } else {
                            document.all.normalBT.disabled = false;
                            document.all.cancelBT.disabled = false;
                        }

                        if(row.state=="2"){//<%=AuditItemState.NORMAL_PASS.getCode()%> 正常
                            document.all.normalBT.disabled = true;
                            document.all.createErrBT.disabled = true;
                        }
                    }
                }

                //提交表单
                function displayItemInfos(row) {
                    $.modal.loading("数据加载中......");
                    refreshBT(row);
                    var data = {"id": row.id};
                    var url = ctx+"oms/paeaAuAuditItem/querySdiImagesByTrade";
                    $.operate.post(url,data,function(result){
                        var splitCharLevel1 = "Level@@@@@";
                        var splitCharLevel2 = "@@@";
                        if(result.code==web_status.SUCCESS){
                            var itemData = (result.taskString).split(splitCharLevel1);
                            var itemInfoDetail = itemData[0];
                            var itemInfoImg = itemData[1];
                            var itemInfoPoint = itemData[2];
                            paeaAutypeName = itemInfoPoint.substring(itemInfoPoint.indexOf("^")+1,itemInfoPoint.length);
                            document.getElementById("auTypeName").value= paeaAutypeName;
                            //刷新监控基本信息
                            CommonTool.replaceExistingWithNewHtml(itemInfoDetail.split("]"));
                            //刷新监控影像信息
                            refreshAuditImg(itemInfoImg.split(splitCharLevel2));
                            $.modal.closeLoading();
                        } else {
                            $.modal.msgError(result.msg);
                        }
                    });
                    $.modal.closeLoading();
                }

                //刷新监控影像
                function refreshAuditImg(itemForImgArray){
                    sdiImageList = itemForImgArray;
                    $('#imageBox').empty();
                    $.each(sdiImageList, function(index, sdiImage) {
                        var imageUrl = sdiImage;
                        $('#imageBox').append('<img name= "img'+index+'" src="'+imageUrl+'" alt="影像">');
                    });
                    $('#imageBox').viewer({inline:true}).viewer('update');
                }

                //显示重点监控 “监督项列表”
                function showRows()
                {
                    var typeName = g_radioValue;
                    var num1=0;
                    var num2=0;
                    var num3=0;
                    var firstDisplayRowIndex="-1";
                    var datas= $('#bootstrap-table').bootstrapTable('getData');
                    //alert(JSON.stringify(datas));
                    if(datas != null && datas != ''){
                        for(var i=0;i<datas.length;i++){
                            var state = datas[i].state;
                            if((typeName.indexOf(state)>=0)||(typeName=="all"))
                            {
                                $('#bootstrap-table').bootstrapTable('showRow', { index: i });
                                if(firstDisplayRowIndex=="-1")
                                {
                                    firstDisplayRowIndex = i;
                                }
                            }else
                            {
                                $('#bootstrap-table').bootstrapTable('hideRow', { index: i });
                                $('#bootstrap-table').bootstrapTable('uncheck', i);
                            }
                            if(state=="1")
                            {num1++;}
                            if(state=="2")
                            {num2++;}
                            if(state=="3")
                            {num3++;}
                            document.all.unAuditNum.innerHTML = num1;
                            document.all.normalNum.innerHTML = num2;
                            document.all.errorNum.innerHTML = num3;
                        }
                        if(firstDisplayRowIndex > -1){//如果有数据，选择第一条，触发选中事件
                            $('#bootstrap-table').bootstrapTable('check', firstDisplayRowIndex);
                        }
                    }
                }
            </script>
        </div>
    </div>
</div>
</body>
</html>